package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.service.MenuService;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RequestMapping("/menu")
@RestController
public class MenuController {

    @Reference
    private MenuService menuService;

    @RequestMapping("/findMenu")
    public List<Map> findMenu(){
         return menuService.findAllMenu();
    }

    @RequestMapping("/findMenuByUser")
    public List<Map> findMenuByUser(){
        User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        String username = user.getUsername();
        return menuService.findMenuByUser(username);
    }
}
